Chris Pollett > Old Classses >
CS174

( Print View )

Student Corner:
  [Grades Sec1]
  [Submit Sec1]
  [Class Sign Up Sec1]
  [
Lecture Notes]
  [Discussion Board]

Course Info:
  [Texts & Links]
  [Topics/Outcomes]
  [Outcomes Matrix]
  [Grading]
  [Class Protocols]
  [HW/Quiz Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Additional Policies]
  [Announcements]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]  [Quizzes]

Practice Exams:
  [Midterm]  [Final]

                           












HW#2 --- last modified February 07 2019 04:37:33..

Solution set.

Due date: Oct 4

Files to be submitted:
  Hw2.zip

Purpose: To develop our first PHP project using a model view controller pattern.

Related Course Outcomes:

The main course outcomes covered by this assignment are:

LO1 -- Write HTML documents containing standard HTML elements including forms, tables, client-side scripts, and server-side scripts.

LO3 -- Write server-side scripts that process HTML forms.

Specification:

For this homework you will create a PHP website called SimpleBlog. If you don't know what a blog is please see the Wikipedia Article and maybe try out WordPress which comes with MAMP and with XAMPP as an optional extra install. Your blog should support an initial front page view of the most recent blog entry. This page has a right side element with a list of entry titles ordered from most recent to oldest. Clicking on these links should go to a page with that blog entry. On any blog entry page, beneath the entry should be a form consisting of a text field labeled Name, beneath this a textarea labelled Comment, and a submit button. Entering data into these and clicking submit should add a comment on this entry. Comments should appear beneath the form ordered from most recent to oldest. At the top right of a blog entry page there should be a link which either says [Login] or says [Logout]. If the state is Logon then clicking this link takes you to another page where the blogger can log on. This page has a form with a textfield labeled username, a password field labeled password, and a submit button. Entering the username pat and the password secret, the blogger can log one. i.e., we assume the system has one user. Logging on takes one to the front page. Above the blog entry links on the right side element there should be an [Add New Entry] link. Clicking this takes the user to a page with a form to add a new blog entry. A blog entry should have a title and some content text at a minimum so design this form accordingly. Also, on the logged in front page next to each right side blog entry link except the oldest, there should be a [Delete] link. Clicking this link deletes that entry and associated comments. Next to each comment there should also be a [Delete] link. Clicking this link deletes the comment. Finally, if one is logged in and one clicks the logout link one should go back to the front page but now in the logged out state. On initial installation of your site, there should be a default first blog entry which is undeletable. So the first time you go to the site, the main page will view this as the most recent blog entry and display it.

Now that we have described what SimpleBlog does, let's describe how the code you submit should be organized as well as how it should work.

You should organize the files of your project as follows:

  • Project Root/
    • index.php
    • config/
    • controllers/
    • models/
    • entries/
    • views/
    • css/

Access to your site will be through URLs of the form:

BASEURL/index.php?c=controllername&a1=arg1&a2=arg2...

Here BASEURL is the URL for where your site is hosted. Nowhere in your code should you hard code/force the value of this. In the general form of the URL above, controllername is the name of the controller requested. It should correspond to the name of a file in the controllers folder. For example, c=foo would say use the file controllers/foo.php as the controller. Remember URLs always use forward slashed, so use controllers/foo.php in your code not controllers\foo.php. The name value pairs a1=arg1, etc. correspond to arguments you would like to send to the given controller -- these may or may not be present depending on the controller. On any access to your site, your index.php script should first include files from the config folder. This folder should contain as few files as possible. The purpose of these files should be to set up any variables that might need to change if you deployed your program on a different site. The config folder should also have a readme.txt file telling the grader what needs to be changed in config files to get your site running. Be aware that making the grader work too hard to get your site running will result in a lower score. The grader has the discretion regardless of the point values listed in the table below to reduce your score to 0 if your site is too hard to deploy.

If the user enters a url of the form just BASEURL or BASEURL/index.php your code should behave as if the url had been

BASEURL/index.php?c=main&view=notloggedin&e=mostrecent

Roughly, this tells the script index.php to require the file controllers/main.php and run it to access the data in the most recent blog entry then display this data using the nonloggedin view. main.php should use functions in the model, models/entry_model.php, to read the data stored in the entries folder concerning the most recent blog entry (we will describe the data format in a moment). Then main.php should set up a $data global which it gives the view views/notloggedin.php to draw the web page that the user sees. The basic split of work is as follows: A controller is used to figure out from the request which models are needed to get data to handle the request. A controller then might do some calculation on the data it gets back from the models. The controller then sets up the $data variable, selects a view and tells it to draw. A model is responsible for accessing storage that persists between requests such as data stored in a file or a database. For example, for SimpleBlog, we will use the model models/entry_model.php to read and write blog entries to and from the filesystem. A controller should never be allowed to directly access the filesystem or database. Finally, a view is responsible for drawing web pages. Neither controllers nor models should ever output anything. A view is not allowed to perform any calculations beyond doing echo's like: <?php echo $data['some_field']; ?>. I will allow your index.php file to render a common header and footer for all pages on your site.

So to implement SimpleBlog, beyond the notloggedin view, you should have a loggedin view. The e argument of the url can also take timestamps of the time when a blog entry was written. The main controller should be used for adding a comment. In this case, the form should be posted, the controller,view, and entry should be hidden variables, and you should have a hidden variable a with value comment. A separate controller, blog.php and view should be used for handling adding a blog post. It can still use the entry.php model. Finally, the login screen should be a separate view and use a separate controller login.php . The model for this controller should be authenticate.php. This model should also be used by main to read and write from $_SESSION to see if a user is logged in or not currently.

Data for blog entries should be stored in the entries folder (the web-server should have read-write-execute permissions on this folder). Within this folder there should be a sequence of folders labeled by timestamps (as given by the PHP time() function), one for each blog entry. the timestamp indicates when the blog entry was written. The default initial blog entry have timestamp 0. Within each of these folders there are two kinds of files: blog.txt containing a blog entry, and files of the form [timestamp].txt where [timestamp] is a timestamp. The latter file contain comments and the timestamp indicates when it was written. The first line up to a newline character in a blog file contains its title, the rest is the content of the blog entry. Similarly, the first line of a comment is the person's name of the commenter, the rest is the content of the comment.

You should try to make your blog look as beautiful as possible. To help with this you should use an external style sheet to style at least the headers on your page, to style a background, and to set a pleasing font. The stylesheet (and code in general) must be entirely your own, no YUI or the like, and it should be placed in the CSS folder. Each page on your site should have a title of the form [Name of Site] - [What on site looking at]. The first h1 header on your page should also say this. Clicking on the [Name of Site] portion of this should also be a link that points back to BASEURL.

Point Breakdown

Folder set-up as described and URLs used as described (1/2pt each)1pt
config directory is used as described and has a readme.txt that is accurate1pt
At least one external stylesheet is used. It should make use of class, and id selectors. It should style at least headers, background, and at least one font used.1pt
The model entries is used whenever a controller needs to read, write, delete blog entries or comments1pt
Blog entries stored in the format described1pt
main.php sets up views as described above.1pt
Login, Logout links works as described.1pt
login.php controller works/sets up views as described above1pt
The blog.php associated views work as described.1pt
authenticate.php model used/works as described, $_SESSION used.1pt
Total10pts